package com.bhs.sansong.ui.order;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.bhs.sansong.R;
import com.bhs.sansong.adapter.LogisticsTrackAdapter;
import com.bhs.sansong.base.BaseActivity;
import com.bhs.sansong.bean.LogisticsTrackData;
import com.bhs.sansong.net.NetCallBack;
import com.bhs.sansong.ui.dialog.MyClickListener;
import com.bhs.sansong.utils.ToastUtil;
import com.google.gson.Gson;

import okhttp3.ResponseBody;
import retrofit2.Response;

/**
 * 物流轨迹
 */
public class LogisticsTrackActivity extends BaseActivity implements NetCallBack, View.OnClickListener {
    private String deliver_sn;
    public ClipData mClipData;   //剪切板Data对象
    public ClipboardManager mClipboardManager;   //剪切板管理工具类
    private LogisticsTrackAdapter logisticsTrackAdapter;
    @Override
    public int initLayout() {
        return R.layout.activity_logistics_track;
    }

    @Override
    public void initView() {
        deliver_sn = getIntent().getStringExtra("deliver_sn");
        TextView mTvWaybillNumber = findViewById(R.id.tv_waybill_number);
        TextView mTvCopy2 = findViewById(R.id.tv_copy2);
        mTvCopy2.setOnClickListener(this);
        FrameLayout mFlClose = findViewById(R.id.fl_close);
        mFlClose.setOnClickListener(this);
        RecyclerView mRvList = findViewById(R.id.rv_list);
        logisticsTrackAdapter = new LogisticsTrackAdapter();
        mRvList.setAdapter(logisticsTrackAdapter);
        mRvList.setLayoutManager(new LinearLayoutManager(mActivity));
        networkRequest(netApi.get_order_logistics(deliver_sn), this, 666);
        mTvWaybillNumber.setText(String.format("订单号：%s", deliver_sn));
    }

    @Override
    public void initData() {

    }

    @Override
    public void onResponse(int requestCode, String json, Response<ResponseBody> response) throws Exception {
        LogisticsTrackData trackData = new Gson().fromJson(json, LogisticsTrackData.class);
        if (trackData.isStatus()) {
            logisticsTrackAdapter.setNewData(trackData.getData().getOrder_logistics_list());
        }
    }

    @Override
    public void onFailure(int requestCode) {

    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.fl_close) {
            finish();
        } else {
            mClipData = ClipData.newPlainText("订单号", deliver_sn);
            mClipboardManager.setPrimaryClip(mClipData);
            ToastUtil.show("复制成功");
        }
    }
}